/*
 * Copyright 2011-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.platform.framework.entity;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 模型基础类
 *
 * @author liym
 * @since 2019-02-22 11:08 新建
 */
public abstract class EntitySupport {

    /// =================== 模型公共参数 ====================
    /** 创建时间 */
    private LocalDateTime createTime;
    /** 创建者 */
    private String creator;
    /** 更新时间 */
    private LocalDateTime updateTime;
    /** 更新者 */
    private String updater;

    /// =================== 页面请求参数 ====================
    /** 请求参数 */
    @JsonIgnore
    private Map<String, Object> params;

    /// =================== 分页请求参数 ====================
    /**
     * 分页：页码，从 1 开始，如 1、2、3……
     */
    @JsonIgnore
    private int pageNo;
    /**
     * 分页：每页显示的数据条数，如 10、20、30……
     */
    @JsonIgnore
    private int pageSize;

    /// =================== 分页返回条数 ====================
    /**
     * 数据总条数，可能为零
     *
     * <p>该参数用于 MyBatis 的拦截器中设置分页数据的总条数</p>
     */
    @JsonIgnore
    private long totalCount;

    /// ===

    protected EntitySupport() {
    }

    public String getCreator() {
        return this.creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public LocalDateTime getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getUpdater() {
        return this.updater;
    }

    public void setUpdater(String updater) {
        this.updater = updater;
    }

    public LocalDateTime getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    /// ===

    public Map<String, Object> getParams() {
        if (this.params == null) {
            this.params = new HashMap<>(8);
        }
        return this.params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    public int getPageNo() {
        return this.pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * toString
     *
     * @return a string representation of the object.
     * @since 2019-02-22 11:21
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_CLASS_NAME_STYLE);
    }

}
